package switchviz.core.signal;

import java.util.List;

import switchviz.core.SwitchVizException;
import switchviz.core.alias.AliasFacade;
import switchviz.core.mib.MIBFacade;

public class SignalUtil
{
	public static ISignal findSignal(List<ISignal> signals, ISignal signal) throws SwitchVizException
	{
		return findSignal(signals, signal.getAliasName(), signal.getPort());
	}
	
	public static ISignal findSignal(List<ISignal> signals, String aliasName, int port) throws SwitchVizException
	{
		try
		{
			boolean portRequired = MIBFacade.isPortRequired(AliasFacade.getOid(aliasName));
			
			for (int i = 0; i < signals.size(); ++i)
				if (aliasName.equals(signals.get(i).getAliasName()))
				{
					if (portRequired == false || port == signals.get(i).getPort())
						return signals.get(i);
				}
			
			return null;
		}
		catch (SwitchVizException e)
		{
			throw new SwitchVizException("Error finding signal.", e);
		}
	}
}
